#include "actor/player.hpp"

#include "game.hpp"
#include "graphics.hpp"
#include "room.hpp"
#include "tile/tilemap.hpp"

namespace nmc
{
	Player::Player()
		: Actor(Point(0, 0), 16, 32)
	{}

	void Player::logic(Room* room)
	{
		Point velocity;
		static int frame = 0;

		if (frame % 2 == 0)
		{
			if (Game::instance()->isUpKeyHeldDown())
			{
				velocity.y -= 1;	
			}
			
			if (Game::instance()->isRightKeyHeldDown())
			{
				velocity.x += 5;	
			}

			if (Game::instance()->isDownKeyHeldDown())
			{
				velocity.y += 14;	
			}

			if (Game::instance()->isLeftKeyHeldDown())
			{
				velocity.x -= 5;	
			}		
		}

		if (Game::instance()->isJumpKeyHeldDown())
		{
			velocity.y = -1;
		}
		else
		{
			velocity.y = 1;
		}


		room->getTileMap()->resolveCollision(this, velocity);
		setPosition(getPosition() + velocity);
		frame++;
	}

	void Player::draw(Graphics* graphics)
	{

	}
}